//
//  NSString+MyString.m
//  DNSBankInfoClient
//
//  Created by Ruichao Wang on 12-10-24.
//
//

#import "NSString+MyString.h"
#import "pinyin.h"

@implementation NSString (MyString)

+ (NSString *) md5:(NSString *)str
{
	const char *cStr = [str UTF8String];
    unsigned char result[16];
    CC_MD5( cStr, strlen(cStr), result );
    return [NSString stringWithFormat:
			@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
			result[0], result[1], result[2], result[3],
			result[4], result[5], result[6], result[7],
			result[8], result[9], result[10], result[11],
			result[12], result[13], result[14], result[15]
			];
}


+(NSString*) replaceParameterURL:(NSString*)orgURL
                          bankId:(NSString*)bankId
                        preferId:(NSString*)preferId
                      pushTaskId:(NSString*)pushTaskId
{
   
    //这个版本先不支持ios特有的参数。
    return nil;
//    return [orgURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
}

+ (NSString *)pinyinWithHanzi:(NSString*)sourceString
{
    
    if (sourceString.length <= 0) {
        return @"#";
    }
    NSString *str = [sourceString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSString *result = [self RemoveSpecialCharacter:str];
    NSMutableString *source = [result mutableCopy];
    CFStringTransform((__bridge CFMutableStringRef)source, NULL, kCFStringTransformMandarinLatin, NO);
    CFStringTransform((__bridge CFMutableStringRef)source, NULL, kCFStringTransformStripDiacritics, NO);
    
    return [source stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}


+(NSString *)namToPinYinFisrtNameWith:(NSString *)name
{
    NSString * outputString = @"";
    for (int i =0; i<[name length]; i++) {
        outputString = [NSString stringWithFormat:@"%@%c",outputString,pinyinFirstLetter([name characterAtIndex:i])];
        
    }
    return outputString;
}


+(NSString*)RemoveSpecialCharacter: (NSString *)str
{
    NSRange urgentRange = [str rangeOfCharacterFromSet: [NSCharacterSet characterSetWithCharactersInString: @",.？、 ~￥#&<>《》()[]{}【】^@/￡¤|§¨「」『』￠￢￣~@#&*（）——+|《》$_€"]];
    if (urgentRange.location != NSNotFound)
    {
        return [self RemoveSpecialCharacter:[str stringByReplacingCharactersInRange:urgentRange withString:@""]];
    }
    return str;
}

@end
